<?php
namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\File;

class Business extends Controller{//首页数据显示
    public function index(){
        $list = Db::table('hotel')->where("type=0")->order("id desc")->paginate(6);//这查的是数
        $page = $list->render();
        $date = Db::table('hotel')->where("type=1")->order("id desc")->paginate(6);//这查的是数
        $pge = $date->render();
        return view("Index",array("data"=>$list,"page"=>$page,"da"=>$date,"pge"=>$pge));
    }
    public function select(){//模糊查询
        $cid = $_POST["cid"];
        $name=$_POST["name"];
        $keywords = $_POST["keywords"];
        if($cid==""&$name==""&$keywords==""){//判断name值是否为空
            $row = Db::name('hotel')->paginate(6);
//            $this->error('查询数据不能为空','index','',1);
        }else{                                                                                           //不否为空进行模糊查询
            $row = Db::table("hotel")->where("
                type like '%{$keywords}'
                or name like '%{$keywords}'
                or name like '%{$keywords}%'")->where("
                name like '%{$cid}'
                or type like '{$cid}%'
                or type like '%{$cid}%'")->where("
                detailed like '%{$name}'
                or detailed like '{$name}%'
                or detailed like '%{$name}%'
                ")->paginate(6);  //查询 细分类的表 找到对应的类名
        }
        $page = $row->render();
        return view('index',array('data'=>$row,'page'=>$page));
    }
    public function add(){
        return view("Business/add");
    }
    public function merchant_submit(){//商家提交

         $file = request()->file("file");
         $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
         $img  = $info->getSaveName();
         
        if(request()->isPost()){//判断是否是post提交
           $data = array(
                'name'=>$_POST['merchant_name'],
                'longitude'=>$_POST['lng'],
                'latitude'=>$_POST['lat'],
                'img'=>$img,
                'phone'=>$_POST['phone'],
                'Mail'=>$_POST['Mail'],
                'introduce'=>$_POST['merchant_introduction'],
                'type'=>$_POST['merchant_if'],
                'detailed'=>$_POST['sever_add'],
            );

            $test = Db::table("hotel")->insert($data);
            if($test){

                $this->success('添加成功','index','',1);

            }else{

            }
         }else{
            echo 0;
         }
    }
}
